﻿package game 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class Chip extends MovieClip	{
		public var valueTf:TextField;
		public var value:Number;
		public var chipName:String;
		
		//determine which is the current frame display of the chip
		private var frameIndex:int = 1;
		private var isActive:Boolean = false;		
		
		public function Chip() {
			this.valueTf.mouseEnabled = false;
			this.buttonMode = true;
			
			this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT, mouseOutHandler);
			this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
		}		
		
		private function mouseOverHandler(e:MouseEvent):void {
			if (!this.isActive) {
				this.gotoAndStop(this.frameIndex);
			}
		}
		
		private function mouseOutHandler(e:MouseEvent):void {
			if (!this.isActive) {
				gotoAndStop(this.frameIndex + 1);
			}
		}
		
		private function mouseDownHandler(e:MouseEvent):void {
			setActive();
		}
		
		/**
		 * @author Daisy
		 */
		public function unActive():void {
			this.isActive = false;
			this.gotoAndStop(this.frameIndex);
		}
		
		/**
		 * @author Daisy
		 */
		public function setActive():void {
			this.isActive = true;
			this.gotoAndStop(this.frameIndex + 2);
		}	
		
		/**
		 * @author Daisy
		 * @param	index
		 */
		public function setFrameIndex(index:int):void {
			this.frameIndex = index;
			this.gotoAndStop(this.frameIndex);
		}
	}
}